#ifndef AABB_H
#define AABB_H

#include "Ray.h"
#include "Geometry.h"
#include "glm/glm.hpp"
#include "Node.h"

using namespace glm;

struct Geometry;

struct AABB {
    vec3 min, max;
    bool intersect(Ray *r);
    bool isLeaf;
    AABB *left, *right;
    Geometry *g;

    AABB *merge(AABB *r);
    /* returns:
     * a negative number if this->min[direction] < other->min[direction]
     * 0 if they're equal
     * a positive number if this > other
     *
     * this assumes the called uses a direction of 0, 1, or 2
     * otherwise we need a branch which the branch predictor in the CPU
     * will always skip.
     */
    float compare(AABB *other, int direction);

    void print();

    AABB() {
        left = NULL;
        right = NULL;
        g = NULL;
        isLeaf = false;
    }
};

AABB *generateBoxes(bNode *boxes, int sortDirection, int num);

#endif
